package ee.roosideSoda.backend.services.implementations;

import java.sql.Connection;

import org.apache.log4j.Logger;

import ee.roosideSoda.backend.database.ConnectionManager;
import ee.roosideSoda.backend.model.dao.KaimasolevaYldkysimuseAndmedDAO;
import ee.roosideSoda.backend.model.dao.factory.DAOFactory;
import ee.roosideSoda.backend.model.data.KaimasolevaYldkysimuseAndmed;
import ee.roosideSoda.backend.services.KaimasolevaYldkysimuseAndmedService;

public class KaimasolevaYldkysimuseAndmedServiceImpl implements KaimasolevaYldkysimuseAndmedService
{
	Logger logger = Logger.getLogger(KaimasolevaYldkysimuseAndmedServiceImpl.class);
	private int INSERTION_WAS_SUCCESSFUL = 1;
	private int INSERTION_WAS_NOT_SUCCESSFUL = 0;
	private int CODE_PRODUCED_AN_ERROR = -1;
	
	private int UPDATE_WAS_SUCCESSFUL = 1;
	private int UPDATE_WAS_NOT_SUCCESSFUL = 0;
	
	int OPERATION_WAS_SUCCESSFUL = 1;
	int OPERATION_WAS_UNSUCCESSFUL = 0;
	//DAOFactory must definitely be  before ConnectionManager, because it initializes ConnectionManager
	//and can potentially do it here
	DAOFactory daoFactory = DAOFactory.getDAOFactory();
	
	@Override
	public KaimasolevaYldkysimuseAndmed saaKaimasolevaYldkysimuseAndmed() 
	{
		Connection dbConnection = ConnectionManager.getInstance().getConnection();
		KaimasolevaYldkysimuseAndmedDAO kaimasolevaYldkysimuseAndmedDAOImpl = daoFactory.getkaimKaimasolevaYldkysimuseAndmedDAOImpl(dbConnection);
		
		KaimasolevaYldkysimuseAndmed kaimasolevaYldkysimuseAndmed = null;
		
		try 
		{
			kaimasolevaYldkysimuseAndmed = kaimasolevaYldkysimuseAndmedDAOImpl.saaKaimasolevaYldkysimuseAndmed();
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error(e.getMessage());
		}
		finally
		{
			ConnectionManager.getInstance().closeConnection();
		}
		
		return kaimasolevaYldkysimuseAndmed;
	}
}
